﻿using mediaControl.Event;
using mediaControl.Utils;
using mediaControl.Vo;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace mediaControl.ViewModels
{
    public class PasswordViewModel : BindableBase, IDialogAware
    {
        public string Title{get;set;}

        public event Action<IDialogResult> RequestClose;

        private string password = "";
        //事件聚合器
        private readonly IEventAggregator eventAggregator;

        public DelegateCommand CloseCommand { get; set; }

        public PasswordViewModel(IEventAggregator eventAggregator)
        {
            ConfirmCommand = new DelegateCommand(confirm);
            CloseCommand = new DelegateCommand(Cancel);
            this.eventAggregator = eventAggregator;
        }

        private void Cancel()
        {
            RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.No));
        }

        private void confirm()
        {
            if (String.IsNullOrEmpty(Password))
            {
                MessageBox.Show("密码不能为空！");
                return;
            }
            if (!Password.Equals("dodacon")) {
                MessageBox.Show("密码不正确！");
                return;
            }
           IDialogParameters parameters = new DialogParameters();
           RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK, parameters));

        }

        /// <summary>
        /// 修改文件，保存文件信息
        /// </summary>
        public DelegateCommand ConfirmCommand { set; get; }

        

        public string Password { get { return password; } set { this.password = value; RaisePropertyChanged(); } }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            
            this.Title = "请输入密码";
        }
    }
}
